package com.zeng.user.validator.bean.validation;

import com.zeng.user.domain.User;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import java.util.Set;

/**
 * @author zyb
 * @date 2021-03-07 14:04
 */
public class BeanValidationDemo {
    public static void main(String[] args) {
        Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
        User user = new User();
        user.setEmail("test@qq.com");
        user.setPassword("12231212");
        user.setPhoneNumber("12343321234");
        Set<ConstraintViolation<User>> violations = validator.validate(user);
        violations.forEach(c -> {
            System.out.println(c.getPropertyPath() + ":" + c.getMessage());
        });
    }
}
